package com.bytedance.scenedemo;

import com.bytedance.scene.group.UserVisibleHintGroupScene;
import com.bytedance.scene.navigation.NavigationSceneGetter;
import com.bytedance.scenedemo.group.async_inflate.AsyncInflateSceneDemo;
import com.bytedance.scenedemo.group.drawer.NavigationViewSample;
import com.bytedance.scenedemo.group.basic_usage.GroupSceneBasicUsageSample;
import com.bytedance.scenedemo.group.hybrid.HybridSample;
import com.bytedance.scenedemo.group.inherited.InheritedDemo;
import com.bytedance.scenedemo.group.placeholder.PlaceHolderViewSample;
import com.bytedance.scenedemo.group.tab.BottomNavigationViewSample;
import com.bytedance.scenedemo.group.viewpager.ViewPagerSample;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;

/**
 * 描述 UI组合
 *
 * @since 2021-05-28
 */
public class GroupSceneUsageSamples extends UserVisibleHintGroupScene {


    private void initLayout(Component layout) {
       final Button button = (Button) layout.findComponentById(ResourceTable.Id_sence_user);
       final Button button2 = (Button) layout.findComponentById(ResourceTable.Id_scene_place_holder);
       final Button tablayout = (Button) layout.findComponentById(ResourceTable.Id_tablayout);//Tablayout + ViewPager
       final Button navigationview = (Button) layout.findComponentById(ResourceTable.Id_navigationview); //侧边栏
       final Button bottomtab = (Button) layout.findComponentById(ResourceTable.Id_bottomtab); //底部tab
       final Button hybird = (Button) layout.findComponentById(ResourceTable.Id_hybird); //混合
       final Button asynchronous_inflate = (Button) layout.findComponentById(ResourceTable.Id_asynchronous_inflate); //异步加载
       final Button extend_scene = (Button) layout.findComponentById(ResourceTable.Id_extend_scene); //继承加载
        button.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(GroupSceneBasicUsageSample.class);
        });
        button2.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(PlaceHolderViewSample.class);
        });
        tablayout.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(ViewPagerSample.class);
        });
        navigationview.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(NavigationViewSample.class);
        });
        bottomtab.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(BottomNavigationViewSample.class);
        });
        hybird.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(HybridSample.class);
        });
        asynchronous_inflate.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(AsyncInflateSceneDemo.class);
        });
        extend_scene.setClickedListener(component -> {
            NavigationSceneGetter.requireNavigationScene(GroupSceneUsageSamples.this).push(InheritedDemo.class);
        });
    }

    @Override
    public ComponentContainer onCreateView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) {
            Component layout = inflater.parse(ResourceTable.Layout_fraction_groupscene_usage_samples, container, false);
            return (ComponentContainer) layout;
        }


    @Override
    public void onViewCreated(Component component, Intent intent) {
        initLayout(component);
        super.onViewCreated(component, intent);
    }
}
